<?php
?>
<div class="content-header">
<table cellspacing="0">
    <tbody><tr>
        <td style="width:50%;"><h3 class="icon-head head-products">出入库管理</h3></td>
        <td class="a-right">
        </td>
    </tr>
</tbody></table>
</div>

<div class="entry-edit">
    <div class="entry-edit-head">
    	<h4 class="icon-head head-edit-form fieldset-legend">商品SKU</h4>
    	<div class="form-buttons"></div>
	</div>
    <div class="fieldset  ignore-validate" id="coupons_information_fieldset">
    <div class="hor-scroll">
    <table cellspacing="0" class="form-list">
        <tbody>
			<tr>
			    <td class="label"><label for="sku">SKU</label></td>
			    <td class="value">
			        <input id="sku" name="sku" value="" title="Dash Every X Characters" class="input-text" type="text"><p class="note" id="note_dash"><span>要操作的商品SKU</span></p>
			    </td>
    		</tr>
			<tr>
        		<td class="label"></td>
			    <td class="value">
			        <span id="coupons_generate_button"><button id="id_3cf81872242ced1ce5317b5704e032c7" title="保存" type="button" class="scalable generate" onclick="generateCouponCodes('coupons_' ,'<?php echo $this->getUrl('admin_zgb/adminhtml_inventory/check')?>', 'warehouseGridJsObject')" style=""><span><span><span>查找</span></span></span></button></span>            </td>
    		</tr>
        </tbody>
    </table>
    </div>
    </div>
</div>
<script type="text/javascript">
	function generateCouponCodes(idPrefix, generateUrl, grid) {
	    $(idPrefix + 'information_fieldset').removeClassName('ignore-validate');
	    var validationResult = $(idPrefix + 'information_fieldset').select('input',
	            'select', 'textarea').collect( function(elm) {
	        return Validation.validate(elm, {
	            useTitle :false,
	            onElementValidate : function() {
	            }
	        });
	    }).all();
	    $(idPrefix + 'information_fieldset').addClassName('ignore-validate');

	    if (!validationResult) {
	        return;
	    }
	    var elements = $(idPrefix + 'information_fieldset').select('input', 'select', 'textarea');

	    elements = elements.concat(
	        $$('#rule_uses_per_coupon'),
	        $$('#rule_uses_per_customer'),
	        $$('#rule_to_date')
	    );

	    var params = Form.serializeElements(elements, true);
	    params.form_key = FORM_KEY;
	    
	    $('messages').update();
	    //var couponCodesGrid = eval(grid);
	    new Ajax.Request(generateUrl, {
	        parameters :params,
	        method :'post',
	        onComplete : function (transport, param){
	            var response = false;
	            if (transport && transport.responseText) {
	                response = eval('(' + transport.responseText + ')');
	            }
	            if(response.error)
	            {
	            	alert(response.message);
	            }
	            else
	            {
	            	//alert(response.url);
	            	setLocation(response.url);
	            }
	            // if (couponCodesGrid) {
	            //     couponCodesGrid.reload();
	            // }
	            // if (response && response.messages) {
	            //     $('messages').update(response.messages);
	            // }
	            // if (response && response.error) {
	            //     alert(response.message);
	            // }
	        }
	    });
	}
</script>
<?php //echo $this->getLayout()->createBlock('zgb/adminhtml_product_tab_warehouse_grid')->toHtml(); ?>